<?php
namespace app\admin\model;
use think\Model;
use think\Db;


class Judge extends Model
{
	public function getDataAll($status){
		$start = input('get.start');
		$end = input('get.end');
		$id = input('get.id');
		$major_id = input('get.major_id');
		$subject_id = input('get.subject_id');
		//只显示状态为传过来的值的数据
		$where ="status = $status";

		//开始时间 
		if ($start) {
			$start = strtotime($start);
			$where .= " and UNIX_TIMESTAMP(add_time) >= $start";
		}
		//结束时间
		if ($end) {
			$end = strtotime($end)+60*60*24;
			$where .= " and UNIX_TIMESTAMP(add_time) <= $end";
		}

		if ($id) {
			$where .= " and id = $id";
		}

		if ($id) {
			$where .= " and id = $id";
		}

		if ($major_id) {
			$where .= " and major_id = $major_id";
		}
		
		if ($subject_id) {
			$where .= " and subject_id = $subject_id";
		}

		// echo $where;
		//当前$this指Admin模型
		$data = Db::name('judge')->where($where)->paginate(10,false,['query'=>array('start'=>$start,'end'=>$end,'id'=>$id,'major_id'=>$major_id,'subject_id'=>$subject_id)]);
		// dump($data);
		return $data;
	} 

	public function addJudge($data){

		$info = Db::name('judge')->where('judge_name',$data['judge_name'])->find();

		if($info){
			return false;
		}


		$data = Db::name('judge')->insert($data);

		return $data;
	}

	public function editJudge($id){
		
		$data = Db::name('judge')->where('id',$id)->find();
		// dump($data);die;
		
		
		return $data;
	}
	
}